package com.haidechizi.designpattern.strategy.extension;

import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

/**
 * @author haidechizi
 */
@Lazy(value = false)
@Component
public class DefaultBarCodeAnalysis extends AbstractBarCodeAnalysis {
    /**
     * 解析条码
     *
     * @param itemCode
     * @return
     */
    @Override
    public BarCode analysis(String itemCode) {
        String type = itemCode.substring(0, 1);
        String code = itemCode.substring(1, 6);
        String price = itemCode.substring(6, 10);
        return new BarCode(Integer.parseInt(type), code, Integer.parseInt(price));
    }

    @Override
    protected String type() {
        return "default";
    }
}
